<template>
	<view class="center">
		<view class="center_top">
			<view class="mask"></view>
		</view>
		<view class="center_box_bg">
			<view class="base">
				<view class="product-box" v-for="(item,index) in collectionList" :key="index">
					<view class="img-box" @click="goToProduct(item.pid)">
						<image :src="item.smallImg" mode="widthFix center" class="img"></image>
					</view>
					<view class="product-name product-common-name">
						{{item.name}}
					</view>
					<view class="product-enname product-common-name">
						{{item.enname}}
					</view>
					<view class="bott">
						<view class="product-price">
							￥{{item.price}}
						</view>
						<u-icon  @click="delCollection(item.pid)"  name="trash"></u-icon>
					</view>
				</view>
				<view style="text-align: center;width: 100%;" v-if="!collectionList">
					<u-empty text="收藏夹为空" mode="list"></u-empty>
				</view>
			</view>
			<view class="baiban"></view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				collectionList: [],
			};
		},
		onLoad() {
			this.getData();
		},
		methods: {
			getData() {
				this.$request({
					url: '/findAllLike',
					success: res => {
						// console.log(res)
						this.collectionList = res.data.result
					}
				});
			},
			delCollection(pid) {
				uni.showModal({
					title: '提示',
					content: '是否删除收藏',
					success: res => {
						if (res.confirm) {
							this.$request({
								url: '/notlike',
								method: 'POST',
								data: {
									pid: pid
								},
								success: res => {
									if (res.data.code == 900) {
										this.getData();
									}
									uni.showToast({
										title: res.data.msg
									})
								}
							});
						} else if (res.cancel) {
						}
					}
				});

			},
			goToProduct(pid) {
				uni.navigateTo({
					url: `/pages/detail/detail?id=${pid}`
				})
			}
		}
	};
</script>

<style lang="scss" scoped>
	page {
		height: 100%;
	}

	.center {
		height: 100%;

		&_top {
			height: 320rpx;
			background-color: #134cdc;

			.mask {
				background: rgba(0, 0, 0, 0.4);
				height: 100%;
			}
		}

		&_box_bg {
			background: #f9f9f9;
			position: relative;

			.baiban {
				background: #fefefe;
			}

			.base {
				position: absolute;
				width: 95%;
				margin: 0 auto;
				top: -100upx;
				left: 2.5%;
				background: #fefefe;
				padding: 35upx 0;
				box-sizing: border-box;
				display: flex;
				flex-direction: row;
				flex-wrap: wrap;
				box-shadow: 0px 2px 5px #ededed;
				border-radius: 30upx;
				// height: 1100rpx;
				overflow-y: auto;

				.product-box {
					width: 200rpx;
					margin-left: 30rpx;
					margin-bottom: 30rpx;
					background-color: #fff;

					.img-box {
						width: 100%;
						height: 200rpx;

						.img {
							width: 100%;
							height: 100%;
							display: block;
						}
					}

					.product-common-name {
						// height: 50rpx;
						text-align: start;
						display: -webkit-box;
						white-space: pre-wrap;
						overflow: hidden;
						text-overflow: ellipsis;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 1;
					}

					.product-name {
						color: #646566;
						font-size: 30rpx;
						margin-top: 20rpx;

					}

					.product-enname {
						color: #b3b5b3;
						font-size: 20rpx;
						height: 40rpx;
					}

					.bott {
						display: flex;
						flex-direction: row;
						align-items: center;
						justify-content: space-between;

						.product-price {
							color: #0c34ba;
							font-size: 32rpx;
							font-weight: bold;
						}
					}

				}
			}
		}
	}
</style>
